﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SARUserControls
{
    /// <summary>
    /// 一种选项卡控件
    /// </summary>
    public partial class SAR_TabSwitchBtn : UserControl
    {
        public SAR_TabSwitchBtn()
        {
            InitializeComponent();
            
        }

        /// <summary>
        /// 鼠标单击事件
        /// </summary>
        public event MouseButtonEventHandler SARClick;

        private bool isSelected = false;
        private bool beenClicked = false;

        /// <summary>
        /// 是否是被选择过的状态
        /// </summary>
        public bool SARBeenClicked
        {
            get
            {
                return beenClicked;
            }
            set
            {
                beenClicked = value;
                if (beenClicked)
                {
                    if (!isSelected)
                    {
                        this.textField.Foreground = new SolidColorBrush(Color.FromRgb(106, 146, 181));
                        this.textField.FontWeight = FontWeights.Bold;
                    }
                }
            }
        }

        /// <summary>
        /// 是否是目前被选择的状态
        /// </summary>
        public bool SARIsSelected
        {
            get
            {
                return isSelected;
            }
            set
            {
                isSelected = value;
                if(isSelected)
                {
                    this.backgroundLev.Visibility = Visibility.Visible;
                    this.textField.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    this.textField.FontWeight = FontWeights.Bold;
                    beenClicked = true;
                }
                else
                {
                    this.backgroundLev.Visibility = Visibility.Hidden;
                    if (!beenClicked)
                    {
                        this.textField.Foreground = new SolidColorBrush(Color.FromRgb(102, 102, 102));
                        this.textField.FontWeight = FontWeights.Normal;
                    }else
                    {
                        this.textField.Foreground = new SolidColorBrush(Color.FromRgb(106, 146, 181));
                        this.textField.FontWeight = FontWeights.Bold;
                    }
                    
                }
            }
        }

        private void sarTab_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            SARIsSelected = true;
            if (SARClick!=null)
            {
                SARClick.Invoke(this,e);
            }
        }

        /// <summary>
        /// 显示的文本
        /// </summary>
        public string SAR_WindowsTxt
        {
            get
            {
                return this.textField.Text;
            }
            set
            {
                this.textField.Text = value;
            }
        }

        /// <summary>
        /// 文本的颜色
        /// </summary>
        public Brush SARTextColor
        {
            set
            {
                this.textField.Foreground = value;
            }
            get
            {
                return this.textField.Foreground;
            }
        }
    }
}
